<? //include/CATEGORY_session.php

include("CATEGORY.php");

require_once'../include/database.php';
$conn = new Connection();
$conn->NewConnection('localhost','ecommerce','root','batavia');
class SessionCATEGORY { 


 
 function find($id){
    
   global $conn;
   
   $query = "select CategoryID,CategoryName,Description,Picture,Active from CATEGORY where CategoryID='$id'";
   
   $run = mysql_query($query) or die(mysql_error());
   
   $row = mysql_fetch_array($run, MYSQL_ASSOC);
   
   $numRow = mysql_numrows($run);
   
   if($numRow)
   
   {
   
   $this->CATEGORY= new CATEGORY();


   
	$this->CATEGORY->setCategoryID($row['CategoryID']);

 
	$this->CATEGORY->setCategoryName($row['CategoryName']);

 
	$this->CATEGORY->setDescription($row['Description']);

 
	$this->CATEGORY->setPicture($row['Picture']);

 
	$this->CATEGORY->setActive($row['Active']);

 
}
return $this->CATEGORY;
}

function insert($CATEGORY){
	global $conn;
	$query = "insert into CATEGORY(CategoryID,CategoryName,Description,Picture,Active) values('".$CATEGORY->getCategoryID()."','".$CATEGORY->getCategoryName()."','".$CATEGORY->getDescription()."','".$CATEGORY->getPicture()."','".$CATEGORY->getActive()."')";
	//$query = "insert into CATEGORY(CategoryName,Description,Picture,Active) values('".$CATEGORY->getCategoryName()."','".$CATEGORY->getDescription()."','".$CATEGORY->getPicture()."','".$CATEGORY->getActive()."')";
 
 $parse=mysql_query($query) or die(mysql_error());

 }
 
 function findall(){
	$query = "select CategoryID,CategoryName,Description,Picture,Active from CATEGORY";
	$parse=mysql_query($query) or die(mysql_error());
	$datas = array();
	while($row=mysql_fetch_assoc($parse))
	{
		$data = array();$data['CategoryID'] = $row['CategoryID'];
		$data['CategoryName'] = $row['CategoryName'];
		$data['Description'] = $row['Description'];
		$data['Picture'] = $row['Picture'];
		$data['Active'] = $row['Active'];
		$datas[] = $data;
	 }
	return $datas;
	}
	function delete($CATEGORY){
	$query = "delete from CATEGORY where CategoryID= '".$CATEGORY->getCategoryID()."'";
	$parse=mysql_query($query);
	return $parse;

	}
	
	function update($CATEGORY){
	$query = "update CATEGORY set CategoryName= '".$CATEGORY->getCategoryName()."',Description= '".$CATEGORY->getDescription()."',Picture= '".$CATEGORY->getPicture()."',Active= '".$CATEGORY->getActive()."' where CategoryID= '".$CATEGORY->getCategoryID()."'";
$parse=mysql_query($query);

}


}
 //include/CATEGORY_session.php